import util from './util';

const draw = {
    clear(ctx, x, y, width, height) {
        ctx.clearRect(x, y, width, height);
    },
    fillRect(ctx, params = {}) {
        const defOpts = {
            x: 0,
            y: 0,
            width: 0,
            height: 0,
            background: '#000000',
        };
        const opts = util.extend(defOpts, params);
        ctx.fillStyle = opts.background;
        ctx.fillRect(opts.x, opts.y, opts.width, opts.height);
    },
    strokeRect(ctx, params = {}) {
        const defOpts = {
            x: 0,
            y: 0,
            width: 0,
            height: 0,
            lineColor: '#000000',
        };
        const opts = util.extend(defOpts, params);
        ctx.lineWidth = opts.lineWidth;
        ctx.strokeStyle = opts.lineColor;
        ctx.strokeRect(opts.x, opts.y, opts.width, opts.height);
    },
    fillText(ctx, params = {}) {
        const defOpts = {
            x: 0,
            y: 0,
            width: 0,
            height: 0,
            content: '',
            color: '#000',
            font: '10px sans-serif',
            textAlign: 'start',
            textBaseline: 'middle',
        };
        const opts = util.extend(defOpts, params);
        ctx.fillStyle = opts.color;
        ctx.textAlign = opts.textAlign;
        ctx.textBaseline = opts.textBaseline;
        ctx.fillText(opts.content, opts.x, opts.y + (opts.height / 2));
        // console.log('text length',ctx.measureText(opts.content).width);
    },
};

export default draw;
